﻿using System;

class SortingArray

            // Sorting an array means to arrange its elements in increasing order. Write a program to sort an array. 
            // Use the "selection sort" algorithm: Find the smallest element, move it at the first position, 
            // find the smallest from the rest, move it at the second position, etc.

{
    static void Main()
    {
        Console.Write("Enter the length of the array:");
        int arraySize = int.Parse(Console.ReadLine());
        int[] array = new int[arraySize];
        Console.WriteLine();

        Console.WriteLine("Enter the elements of the array:");
        for (int i = 0; i < arraySize; i++)
        {
            array[i] = int.Parse(Console.ReadLine());
        }

        int tempMin = 0;
        int temp = 0;
        for (int i = 0; i < array.Length - 1; i++)
        {
            tempMin = i;
            for (int j = i + 1; j < array.Length; j++)
            {
                if (array[j] < array[tempMin])
                {
                    tempMin = j;
                }
            }
            temp = array[i];
            array[i] = array[tempMin];
            array[tempMin] = temp;
        }
        Console.WriteLine();
        Console.WriteLine("The sorted array looks like:");
        for (int i = 0; i < array.Length; i++)
        {
            Console.Write(array[i] + " ");
        }
        Console.WriteLine();
    }
}

